package com.neuedu.cockpit.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.neuedu.cockpit.common.Encode;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.neuedu.common.annotation.Log;
import com.neuedu.common.core.controller.BaseController;
import com.neuedu.common.core.domain.AjaxResult;
import com.neuedu.common.enums.BusinessType;
import com.neuedu.cockpit.domain.HmMedia;
import com.neuedu.cockpit.service.IHmMediaService;
import com.neuedu.common.utils.poi.ExcelUtil;
import com.neuedu.common.core.page.TableDataInfo;

/**
 * 多媒体信息Controller
 * 
 * @author neuedu
 * @date 2024-04-25
 */
@RestController
@RequestMapping("/cockpit/media")
public class HmMediaController extends BaseController
{
    @Autowired
    private IHmMediaService hmMediaService;

    /**
     * 查询多媒体信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HmMedia hmMedia)
    {
        startPage();
        hmMedia.setFileName(Encode.encodeStr(hmMedia.getFileName()));
        hmMedia.setResourceName(Encode.encodeStr(hmMedia.getResourceName()));
        hmMedia.setAuthor(Encode.encodeStr(hmMedia.getAuthor()));
        List<HmMedia> list = hmMediaService.selectHmMediaList(hmMedia);
        return getDataTable(list);
    }

    /**
     * 查询多媒体信息列表（不分页）
     * @param hmMedia
     * @return
     */
    @GetMapping("/alllist")
    public AjaxResult alllist(HmMedia hmMedia)
    {
        List<HmMedia> list = hmMediaService.selectHmMediaListOrderByLike(hmMedia);
        return AjaxResult.success(list);
    }

//    /**
//     * 导出多媒体信息列表
//     */
//    @PreAuthorize("@ss.hasPermi('cockpit:media:export')")
//    @Log(title = "多媒体信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, HmMedia hmMedia)
//    {
//        List<HmMedia> list = hmMediaService.selectHmMediaList(hmMedia);
//        ExcelUtil<HmMedia> util = new ExcelUtil<HmMedia>(HmMedia.class);
//        util.exportExcel(response, list, "多媒体信息数据");
//    }

    /**
     * 获取多媒体信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(hmMediaService.selectHmMediaById(id));
    }

    /**
     * 新增多媒体信息
     */
    @Log(title = "多媒体信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HmMedia hmMedia)
    {
        hmMedia.setCreateBy(getUsername());
        return toAjax(hmMediaService.insertHmMedia(hmMedia));
    }

    /**
     * 修改多媒体信息
     */
    @Log(title = "多媒体信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HmMedia hmMedia)
    {
        return toAjax(hmMediaService.updateHmMedia(hmMedia));
    }

    /**
     * 删除多媒体信息
     */
    @Log(title = "多媒体信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hmMediaService.deleteHmMediaByIds(ids));
    }
}
